/**
 * Created by 游永年 on 2019-01-13 16:28.
 * 测试题顶部标题显示,模块名称和当前题号
 */

import {WhiteSpace, WingBlank} from "antd-mobile";
import React, {Component} from 'react';
import {connect} from 'dva';
import style from './TestQuiz.less';

class Title extends Component {
  render() {
    const {titleName, currIndex, totalNum} = this.props;
    return (
      <div className={style.wrap}>
        <WhiteSpace/>
        <WingBlank>
          <span className={style.title}>{titleName}</span>
          <span className={style.questionNum}>{currIndex + 1}/{totalNum}</span>
        </WingBlank>
      </div>
    );
  }
}

Title.propTypes = {};

const opts = ({quiz}) => {
  const {txList = [], quizList = [], currIndex = 0} = quiz || {};
  const {questionType = "1"} = quizList[currIndex] || {};

  const {name} = txList.find(({typeId = ""}) => typeId === questionType);

  //总题数
  const totalNum = quizList.length;

  return {
    titleName: name,
    currIndex,
    totalNum,
  };
};

export default connect(opts)(Title);
